package problems.daily;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 1817. 查找用户活跃分钟数
 * <p>https://leetcode.cn/problems/finding-the-users-active-minutes/</p>
 *
 * @author habitplus
 * @since 11:32, 2023/1/20
 */
public class DT1817 {

    public int[] findingUsersActiveMinutes(int[][] logs, int k) {
        HashMap<Integer, Set<Integer>> idMap = new HashMap<>();
        Set<Integer> tmpSet;
        for (int[] log : logs) {
            tmpSet = idMap.get(log[0]);
            if (tmpSet == null) {
                tmpSet = new HashSet<>();
                tmpSet.add(log[1]);
                idMap.put(log[0], tmpSet);
            } else {
                tmpSet.add(log[1]);
            }
        }

        int cnt;
        int[] ret = new int[k];

        for (Map.Entry<Integer, Set<Integer>> e : idMap.entrySet()) {
            if ((cnt = e.getValue().size()) <= k) {
                ++ret[cnt - 1];
            }
        }

        return ret;
    }
}
